package com.dormms.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dormms.dto.UserRoleDto;
import com.dormms.service.LoginService;


@Controller
public class LoginController {
	@Autowired
	private LoginService loginService; 
	
	@RequestMapping(value="login.do",method=RequestMethod.POST)
	@ResponseBody
	public String login(String userid, String password, HttpSession session) {
		if(loginService.isLegalUser(userid, password)) {
			UserRoleDto userRoleDto = loginService.getUserRoleByUserId(userid);
			//将用户角色信息存于session中
			session.setAttribute("userRoleDto", userRoleDto);
			return userRoleDto.getRoleName();
		}
		return "illegal";
	}

	public LoginService getLoginService() {
		return loginService;
	}

	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}
}
